var typeLib = require('../type')
var pathLib = require('path')
var first = require('array-first')


function arrayFirst (arr, num) {
	if(!Array.isArray(arr)) {
		throw new TypeError('the first argument must be an array')
	}

	if (arr.length === 0) {
		return null;
	}
	
	// num的默认值为1
	num = typeLib.isNumeric(num) ? +num : 1
	var first = arr.slice(0, num)
	if(num === 1) {
		return first[0]
	}
	return first
}






console.group()
console.log( first(['a', 'b', 'c', 'd', 'e', 'f']) );
//=> 'a'

console.log( first(['a', 'b', 'c', 'd', 'e', 'f'], 1) );
//=> 'a'

console.log( first(['a', 'b', 'c', 'd', 'e', 'f'], 31) );
//=> ['a', 'b', 'c']
console.groupEnd()

console.log('\n-----------------------\n')

console.group(pathLib.basename(__filename))
console.log( arrayFirst(['a', 'b', 'c', 'd', 'e', 'f']) );
//=> 'a'

console.log( arrayFirst(['a', 'b', 'c', 'd', 'e', 'f'], 1) );
//=> 'a'

console.log( arrayFirst(['a', 'b', 'c', 'd', 'e', 'f'], 31) );
//=> ['a', 'b', 'c']
console.groupEnd()
